package com.umakr.ax.utils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author 唐腾飞
 * @des 各种验证码生成器
 */
public class CodeGenerateUtil {

    /**
     * 随机生成4位 纯数字验证码
     * @return
     */
    public static String getFourDigitsPureNumVerifyCode(){
        String[] beforeShuffle = new String[] { "0","1","2", "3", "4", "5", "6", "7", "8", "9" };
        List list = Arrays.asList(beforeShuffle);
        Collections.shuffle(list);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i));
        }
        return sb.toString().substring(2, 6);
    }

    /**
     * 随机生成4位 包含数字和大写字母的验证码
     * 数字不包含 0和1 防止和字幕 I和O 混淆
     * @return
     */
    public static String getFourDigitsNumStrMixingVerifyCode(){
        String[] beforeShuffle = new String[] { "2", "3", "4", "5", "6", "7",
                "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
                "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
                "W", "X", "Y", "Z" };
        List list = Arrays.asList(beforeShuffle);
        Collections.shuffle(list);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i));
        }
        String afterShuffle = sb.toString();
        return afterShuffle.substring(5, 9);
    }

    public static void main(String[] args) {
        System.out.printf(getFourDigitsPureNumVerifyCode());
    }
}
